```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>归并排序算法详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 2px;
            width: 100%;
            height: 8px;
            background-color: rgba(110, 142, 251, 0.3);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 14px;
            background-color: rgba(110, 142, 251, 0.4);
        }
        .step-icon {
            width: 40px;
            height: 40px;
            background-color: #6e8efb;
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 16px;
            flex-shrink: 0;
        }
        .timeline-item {
            position: relative;
            padding-left: 60px;
            margin-bottom: 30px;
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 20px;
            top: 0;
            height: 100%;
            width: 2px;
            background-color: #e2e8f0;
        }
        .timeline-dot {
            position: absolute;
            left: 0;
            top: 0;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #6e8efb;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-28">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <div class="mb-6 px-4 py-2 bg-white bg-opacity-20 rounded-full inline-flex items-center">
                    <i class="fas fa-code mr-2"></i>
                    <span class="text-sm font-medium">算法与数据结构</span>
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">归并排序算法详解</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mb-8">通过分治策略实现的高效排序算法，时间复杂度稳定为 O(n log n)</p>
                <button class="px-8 py-3 bg-white text-indigo-600 rounded-full font-semibold hover:bg-gray-100 transition-all transform hover:scale-105 shadow-lg">
                    开始学习 <i class="fas fa-arrow-right ml-2"></i>
                </button>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12 md:py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="flex flex-col md:flex-row items-start">
                <div class="md:w-2/3 md:pr-10">
                    <h2 class="text-3xl font-bold mb-6 text-gray-800">算法简介</h2>
                    <p class="text-lg text-gray-700 mb-6">
                        归并排序（<span class="font-semibold text-indigo-600">Merge Sort</span>）是一种基于分治策略的排序算法，具有良好的时间复杂度，通常用于大规模数据排序。其主要思想是将待排序的数组分割成较小的部分，分别对这些部分进行排序，然后将排序好的部分合并成最终的排序结果。
                    </p>
                    <div class="bg-indigo-50 border-l-4 border-indigo-500 p-4 rounded-r mb-8">
                        <div class="flex">
                            <div class="flex-shrink-0 text-indigo-500">
                                <i class="fas fa-lightbulb text-xl"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-indigo-700">
                                    <span class="font-semibold">核心思想：</span>
                                    分而治之（Divide and Conquer），将问题分解为更小的子问题，解决子问题后合并结果。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/3 bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-info-circle text-indigo-500 mr-2"></i> 关键特点
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>时间复杂度：O(n log n)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>空间复杂度：O(n)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>稳定排序算法</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>适合大规模数据排序</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Algorithm Steps -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800">归并排序的三大步骤</h2>
            
            <div class="grid md:grid-cols-3 gap-8">
                <!-- Step 1 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-indigo-600 p-4 text-white">
                        <div class="flex items-center">
                            <div class="step-icon">1</div>
                            <h3 class="text-xl font-bold">分解 (Divide)</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            递归地将原数组分成两半，直到每个子数组只包含一个元素或为空（此时子数组自然是已排序的）。
                        </p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <pre class="text-sm text-gray-800">mergeSort(arr, left, right) {
  if (left < right) {
    mid = (left + right) / 2;
    mergeSort(arr, left, mid);
    mergeSort(arr, mid+1, right);
    ...
  }
}</pre>
                        </div>
                    </div>
                </div>
                
                <!-- Step 2 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-purple-600 p-4 text-white">
                        <div class="flex items-center">
                            <div class="step-icon">2</div>
                            <h3 class="text-xl font-bold">解决 (Conquer)</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            对每个分割后的子数组进行排序，递归地处理每个子数组。当子数组长度为1时，自然是有序的。
                        </p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <pre class="text-sm text-gray-800">// 基线条件：子数组长度为1
if (left >= right) {
  return;
}</pre>
                        </div>
                    </div>
                </div>
                
                <!-- Step 3 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-pink-600 p-4 text-white">
                        <div class="flex items-center">
                            <div class="step-icon">3</div>
                            <h3 class="text-xl font-bold">合并 (Combine)</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            将两个已排序的子数组合并成一个排序好的数组。通过比较两个子数组的元素，将较小的元素放入结果数组。
                        </p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <pre class="text-sm text-gray-800">while (i < n1 && j < n2) {
  if (L[i] <= R[j]) {
    arr[k++] = L[i++];
  } else {
    arr[k++] = R[j++];
  }
}</pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800">算法可视化</h2>
            
            <div class="bg-white rounded-xl shadow-md p-6 mb-10">
                <h3 class="text-xl font-semibold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-project-diagram text-indigo-500 mr-2"></i> 归并排序过程演示
                </h3>
                <div class="mermaid">
                    graph TD
                    A[38, 27, 43, 3, 9, 82, 10] --> B[38, 27, 43, 3]
                    A --> C[9, 82, 10]
                    B --> D[38, 27]
                    B --> E[43, 3]
                    D --> F[38]
                    D --> G[27]
                    E --> H[43]
                    E --> I[3]
                    F --> J[27, 38]
                    G --> J
                    H --> K[3, 43]
                    I --> K
                    J --> L[3, 27, 38, 43]
                    K --> L
                    C --> M[9, 82]
                    C --> N[10]
                    M --> O[9]
                    M --> P[82]
                    O --> Q[9, 82]
                    P --> Q
                    N --> R[10]
                    Q --> S[9, 10, 82]
                    R --> S
                    L --> T[3, 9, 10, 27, 38, 43, 82]
                    S --> T
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">时间复杂度分析</h3>
                    <div class="bg-white rounded-lg shadow-sm p-4">
                        <div class="flex items-center mb-3">
                            <div class="w-8 h-8 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-clock text-indigo-500"></i>
                            </div>
                            <span class="font-medium">最优情况：O(n log n)</span>
                        </div>
                        <div class="flex items-center mb-3">
                            <div class="w-8 h-8 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-clock text-indigo-500"></i>
                            </div>
                            <span class="font-medium">最差情况：O(n log n)</span>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-clock text-indigo-500"></i>
                            </div>
                            <span class="font-medium">平均情况：O(n log n)</span>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">空间复杂度分析</h3>
                    <div class="bg-white rounded-lg shadow-sm p-4">
                        <div class="flex items-center">
                            <div class="w-8 h-8 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-memory text-indigo-500"></i>
                            </div>
                            <span class="font-medium">空间复杂度：O(n)</span>
                        </div>
                        <p class="text-sm text-gray-600 mt-2">
                            归并排序需要额外的存储空间来存放临时数组，递归调用也会占用栈空间。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Example -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800">Java 实现示例</h2>
            
            <div class="code-block p-4 md:p-6 rounded-lg overflow-hidden">
                <div class="flex justify-between items-center mb-4">
                    <div class="flex space-x-2">
                        <div class="w-3 h-3 rounded-full bg-red-500"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <div class="text-gray-400 text-sm">MergeSortDemo.java</div>
                </div>
                <pre class="text-gray-300 text-sm md:text-base overflow-x-auto"><code>public class MergeSortDemo {

    // 主函数：归并排序
    public static void mergeSort(int[] arr, int left, int right) {
        if (left < right) {
            int mid = (left + right) / 2;
            // 递归排序左半部分
            mergeSort(arr, left, mid);
            // 递归排序右半部分
            mergeSort(arr, mid + 1, right);
            // 合并两个已排序的部分
            merge(arr, left, mid, right);
        }
    }

    // 合并函数：将两个已排序的子数组合并为一个排序好的数组
    private static void merge(int[] arr, int left, int mid, int right) {
        // 计算子数组的大小
        int n1 = mid - left + 1;
        int n2 = right - mid;
        
        // 创建临时数组
        int[] L = new int[n1];
        int[] R = new int[n2];
        
        // 拷贝数据到临时数组
        System.arraycopy(arr, left, L, 0, n1);
        System.arraycopy(arr, mid + 1, R, 0, n2);
        
        // 合并临时数组
        int i = 0; // 初始左子数组的索引
        int j = 0; // 初始右子数组的索引
        int k = left; // 初始合并数组的索引
        
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k++] = L[i++];
            } else {
                arr[k++] = R[j++];
            }
        }
        
        // 拷贝剩余元素
        while (i < n1) {
            arr[k++] = L[i++];
        }
        
        while (j < n2) {
            arr[k++] = R[j++];
        }
    }

    // 主函数：测试归并排序
    public static void main(String[] args) {
        int[] arr = {38, 27, 43, 3, 9, 82, 10};
        mergeSort(arr, 0, arr.length - 1);
        System.out.println("排序后的数组：");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}</code></pre>
            </div>
            
            <div class="mt-8 grid md:grid-cols-2 gap-6">
                <div class="bg-indigo-50 rounded-lg p-6">
                    <h3 class="text-xl font-semibold mb-3 text-indigo-800">代码解析</h3>
                    <ol class="list-decimal list-inside space-y-2 text-gray-700">
                        <li><code>mergeSort</code> 方法是递归入口，负责分割数组</li>
                        <li>基线条件是子数组长度为1时停止递归</li>
                        <li><code>merge</code> 方法负责合并两个已排序的子数组</li>
                        <li>使用双指针技术比较和合并两个子数组</li>
                        <li>最后处理剩余未比较的元素</li>
                    </ol>
                </div>
                <div class="bg-green-50 rounded-lg p-6">
                    <h3 class="text-xl font-semibold mb-3 text-green-800">执行结果</h3>
                    <div class="bg-gray-800 rounded p-4">
                        <p class="text-green-400 font-mono">排序后的数组：</p>
                        <p class="text-white font-mono">3 9 10 27 38 43 82</p>
                    </div>
                    <p class="mt-3 text-sm text-gray-600">输入数组 [38, 27, 43, 3, 9, 82, 10] 经过归并排序后得到有序数组。</p>
                </div>
            </div>
        </section>

        <!-- Comparison -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800">与其他排序算法对比</h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white rounded-lg overflow-hidden shadow">
                    <thead class="bg-gray-100">
                        <tr>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">排序算法</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">最佳时间复杂度</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">最差时间复杂度</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">平均时间复杂度</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">空间复杂度</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">稳定性</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr>
                            <td class="py-3 px-4 font-medium">归并排序</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n)</td>
                            <td class="py-3 px-4"><span class="bg-green-100 text-green-800 py-1 px-2 rounded-full text-xs">稳定</span></td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 font-medium">快速排序</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n²)</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(log n)</td>
                            <td class="py-3 px-4"><span class="bg-red-100 text-red-800 py-1 px-2 rounded-full text-xs">不稳定</span></td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 font-medium">堆排序</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(n log n)</td>
                            <td class="py-3 px-4">O(1)</td>
                            <td class="py-3 px-4"><span class="bg-red-100 text-red-800 py-1 px-2 rounded-full text-xs">不稳定</span></td>
                        </tr>
                        <tr>
                            <td class="py-3 px-4 font-medium">冒泡排序</td>
                            <td class="py-3 px-4">O(n)</td>
                            <td class="py-3 px-4">O(n²)</td>
                            <td class="py-3 px-4">O(n²)</td>
                            <td class="py-3 px-4">O(1)</td>
                            <td class="py-3 px-4"><span class="bg-green-100 text-green-800 py-1 px-2 rounded-full text-xs">稳定</span></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <div class="mt-8 bg-blue-50 rounded-lg p-6">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-star text-yellow-500 text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-semibold text-blue-800">何时选择归并排序？</h3>
                        <p class="mt-2 text-blue-700">
                            归并排序在需要稳定排序且数据规模较大时是很好的选择。特别适用于链表排序、外部排序等场景。虽然需要额外空间，但其时间复杂度稳定为 O(n log n)，不受数据初始顺序影响。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Applications -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800">实际应用场景</h2>
            
            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-4xl mb-4">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">大规模数据排序</h3>
                    <p class="text-gray-600">
                        归并排序的 O(n log n) 时间复杂度使其非常适合处理大规模数据集，如数据库排序、大数据处理等场景。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-4xl mb-4">
                        <i class="fas fa-code-branch"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">链表排序</h3>
                    <p class="text-gray-600">
                        归并排序是链表排序的首选算法，因为链表的随机访问性能差，而归并排序只需要顺序访问。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-4xl mb-4">
                        <i class="fas fa-hdd"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">外部排序</h3>
                    <p class="text-gray-600">
                        当数据量太大无法全部加载到内存时，归并排序可以高效地处理外存中的数据，常用于数据库系统和文件系统。
                    </p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col items-center">
                <div class="mb-4">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                </div>
                <div class="mb-6">
                    <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors">
                        <i class="fas fa-link mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="text-gray-500 text-sm">
                    © 2023 技术小馆. All rights reserved.
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 添加滚动动画效果
        document.addEventListener('DOMContentLoaded', function() {
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        entry.target.classList.add('animate-fadeInUp');
                    }
                });
            }, {
                threshold: 0.1
            });
            
            document.querySelectorAll('section').forEach(section => {
                observer.observe(section);
            });
        });
    </script>
</body>
</html>
```